//run.cpp
#include "Time.hpp"
#include <iostream>
#include <string>
#include <ctime>
#include <cmath>
using namespace std;
Time* timeDifference(Time&, Time&);  //求时间差的函数（求的是绝对值）

int main() {    //通过随机数函数来创建两个Time对象
    srand((int)time(0));    //设置随机数种子    
    int hour = rand() % 24; 
    int minute = rand() % 60;
    int second = rand() % 60;
    Time time1 = Time(hour, minute, second);
    cout << "time1：" << time1.getTime() << endl;

    hour = rand() % 24;
    minute = rand() % 60;
    second = rand() % 60;
    Time time2 = Time(hour, minute, second);
    cout << "time2：" <<time2.getTime() << endl;
    
    Time *timeSub = timeDifference(time1, time2);
    cout << "两者的时间差为：" << timeSub->getTime() << endl;
    
    return 0;
}

Time* timeDifference(Time& time1, Time& time2) {
    Time *temp = new Time();
    int totalSecond1 = time1.getSecond() + time1.getMinute() * 60 + time1.getHour() * 60 * 60;
    int totalSecond2 = time2.getSecond() + time2.getMinute() * 60 + time2.getHour() * 60 * 60;
    int subOfSecond = abs(totalSecond1 - totalSecond2);
    temp->setSecond(subOfSecond % 60);
    temp->setMinute(subOfSecond / 60 % 60);
    temp->setHour(subOfSecond / 3600);
    return temp;
}
